<?php
include_once "wcapi_opensearch.php";
$key = "AMDHCmf0v6LFGqQ0veCwv5sISTqNoo3cre4zAMMZ6h02e4sW9qmPPVKNSXk0DeTAP05vsjXcoknZUt86";
//$query = "Things fall apart";
$format = "rss";
$start = 1;
$count  = 10;
$cformat = "apa";
?>
<html>
	<head>
		<title>Checking API</title>
	</head>
	<body>
		<form action="index.php" method="POST">
			<p>Please type your query here Obby, <input type="text" value="<?php echo $_POST['query'];?>" name="query"/>&nbsp;<input type="submit" value="Submit"></p>
			<hr/>
			<?php
				if (isset($_POST['query']) && $_POST['query'] != "")
				{					
					$query = $_POST['query'];
					$data = worldcat_opensearch($key,$query,$format,$start,$count,$cformat);					
					var_export($data);
					if (count($data) > 0)
					{
						$item = $data[0];						
						$text = $item['content'];
						echo $text . "<br/>";
						$pos = strpos($text, ": ");
						if ($pos > 0)
						{
							$small = substr($text, 0, $pos);
							$temp = strrev($small);							
							$pos = strpos($temp, " .");
							if ($pos > 0)
							{
								$data = substr($small, strlen($temp) - $pos);
								echo "<br/>$data";
							}							
						}
					}					
				}
			?>
		</form>
	</body>
</html>